<template>
  <Container class="dealer-info-list">
    <HeadFormItem
      slot="header"
      :list="list"
      @onSearchBtnClick="onSearchBtnClick"
      @onAddBtnClick="onAddBtnClick"
    />
    <Tabs v-model="tab">
      <TabPane label="经销商信息列表" name="tab1">
        <homeTable
          :list="list"
          :border="true"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
          @onSelectionChange="onSelectionChange"
        />
      </TabPane>
    </Tabs>
    <DealerBindModelItem ref="supplerBind" />
  </Container>
</template>
<script>
import DealerInfoListData from './list/DealerInfoListData'
import HeadFormItem from './list/HeadFormItem'
import DealerBindModelItem from './list/DealerInfoModelItem'
import homeTable from '@/components/homeTable'

import { clearEmpty } from '@/util'
export default {
  components: {
    HeadFormItem,
    DealerBindModelItem,
    homeTable
  },
  data() {
    return {
      tab: "tab1",
      list: DealerInfoListData,
      productIds: []
    };
  },
  mounted() {
    this.list.currentPage = ~~this.$route.query.currentPage || 1;
    this.list.pageSize = ~~this.$route.query.pageSize || this.list.pageSize;
    this.getData();
    this.$bus.$on('bindRow', this.supplerBindOpen)
    this.$bus.$on('detailRow', this.supplersignInfo)
    this.$bus.$on('editRow', this.supplersignEdit)
  },
  destroyed() {
    this.$bus.$off();
  },
  methods: {
    onSearchBtnClick() {
      this.list.currentPage = 1;
      this.getData();
    },
    onAddBtnClick() {
      this.$router.push({
        name: 'manage/dealer/edit'
      })
    },
    supplersignEdit() {
      this.$router.push({
        name: 'manage/dealer/edit',
        query: {
          id: 12313
        }
      })
    },
    supplersignInfo() {
      this.$router.push({
        name: 'manage/dealer/edit',
        query: {
          id: 12313
        }
      })
    },
    supplerBindOpen() {
      this.$refs.supplerBind.openModal()
    },
    getData() {
      this.productIds = [];
      return;
      this.list.status = "loading";
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        isShelf: this.list.form.isShelf,
        code: this.list.form.code,
        categoryId: this.list.form.categoryId,
        brandId: this.list.form.brandId,
        keyword: this.list.form.keyword
      };
      param = clearEmpty(param)
      this.$jsonPost("/product/product_info/page_product_info_and_tags", param).then(data => {
          this.list.data = [];
          this.list.totalItem = Number(data.total);
          this.list.totalItem = Number(data.total);
          this.list.data = (data.records || []).map(item => {
            return {
              id: item.productInfoDTO.id,
              sn: item.productInfoDTO.idToBase62Str,
              categoryName: item.productInfoDTO.categoryName,
              title: item.productInfoDTO.title,
              code: item.productInfoDTO.code,
              unit: item.productInfoDTO.unit,
              isShelf: item.productInfoDTO.isShelf,
              brandName: item.productInfoDTO.brandName,
              salePrice: item.productSkuDTO.salePrice,
              marketPrice: item.productSkuDTO.marketPrice,
              costPrice: item.productSkuDTO.costPrice,
              tagName: item.productIdTagNameDTO ? item.productIdTagNameDTO.tagName : "",
              skuId: item.productSkuDTO.id
            };
          });
          this.list.status = "pass";
          this.backTableTop();
        })
        .catch(() => {
          this.list.status = "error";
        });
    },
    onSelectionChange(selection) {
      this.productIds = (selection || []).map(item => item.id);
    },
    onPageChange(number) {
      this.list.currentPage = number;
      this.$router.push({
        name: "manage/dealer/list",
        query: {
          currentPage: this.list.currentPage,
          pageSize: this.list.pageSize
        }
      });
      this.getData();
    },
    onPageSizeChange(pageSize) {
      this.list.currentPage = 1;
      this.list.pageSize = pageSize;
      this.$router.push({
        name: "manage/dealer/list",
        query: {
          currentPage: this.list.currentPage,
          pageSize: this.list.pageSize
        }
      });
      this.getData();
    },
    onRefresh() {
      this.getData();
    },
    onExport() {
      this.$Message.info('导出')
    },
  },
  watch: {
  }
};
</script>
